import r from '@/router/axios'
import { LoginDTO, SmsLoginDTO } from '@/types/User/dto'
import { api, initalAppendForm, initalHeader } from './config'

export const loginReq = (data: LoginDTO) => {
  return r.request<UserTokenVO>({
    url: api.login,
    method: 'POST',
    headers: initalHeader,
    params: {
      ...data,
      ...initalAppendForm(),
    },
  })
}

export const smsLoginReq = (data: SmsLoginDTO) => {
  const smsLoginDto = new SmsLoginDTO(data)
  return r.request<UserTokenVO>({
    url: api.smsLogin,
    headers: initalHeader,
    method: "POST",
    params: {
      ...smsLoginDto,
      ...initalAppendForm('mobile'),
    },
  });
};

export const logoutReq = () => {
  return r.request<R<boolean>>({
    url: api.logout,
    method: 'DELETE',
  })
}